<script setup>
import {getOrderAPI} from "@/apis/order"
import { onMounted, ref } from "vue";
import {useRoute,useRouter} from "vue-router"

const route = useRoute()
const router = useRouter()
const payInfo = ref({})
const dialogVisible = ref(false)
const getOrderInfo = async () => {
  const res = await getOrderAPI(route.query.id)
  payInfo.value = res.result

}

const payHandle = (payTitle) => {
  router.push({
    path: 'payCallback',
    query: {
      id: route.query.id,
      pay: payTitle === '微信支付' ? 1 : 2
    }
  })
}

const payTitle = ref('')
const payTypeHandle = (payType) => {
  dialogVisible.value = true
  payTitle.value = payType === 1 ? '微信支付' : '支付宝支付'
}
onMounted(() => {
  getOrderInfo()
})


</script>

<template>
  <div class="xtx-pay-page">
    <div class="container">
      <!-- 付款信息 -->
      <div class="pay-info">
        <span class="icon iconfont icon-queren2"></span>
        <div class="tip">
          <p>订单提交成功！请尽快完成支付。</p>
          <!-- <p>支付还剩 <span>24分30秒</span>, 超时后将取消订单</p> -->
        </div>
        <div class="amount">
          <span>应付总额：</span>
          <span>¥{{ payInfo.payMoney?.toFixed(2) }}</span>
        </div>
      </div>
      <!-- 付款方式 -->
      <div class="pay-type">
        <p class="head">选择以下支付方式付款</p>
        <div class="item">
          <p>支付平台</p>
          <a class="btn wx" href="javascript:;" @click="payTypeHandle(1)"></a>
          <!-- <a class="btn alipay" :href="payUrl"></a> -->
          <a class="btn alipay" @click="payTypeHandle(2)"></a>
        </div>

      </div>
    </div>
  </div>


   <!-- 弹框 -->
   <el-dialog v-model="dialogVisible" :title="payTitle" width="30%">
      <span>请确认支付信息:</span>
      <div class="amount" style="margin-top: 20px;">
          <span>支付总额：</span>
          <span style="color:red;">¥{{ payInfo.payMoney?.toFixed(2) }}</span>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="payHandle(payTitle)">确认支付</el-button>
        </span>
      </template>
    </el-dialog>



</template>

<style scoped lang="scss">
.xtx-pay-page {
  margin-top: 20px;
}

.pay-info {

  background: #fff;
  display: flex;
  align-items: center;
  height: 240px;
  padding: 0 80px;

  .icon {
    font-size: 80px;
    color: #1dc779;
  }

  .tip {
    padding-left: 10px;
    flex: 1;

    p {
      &:first-child {
        font-size: 20px;
        margin-bottom: 5px;
      }

      &:last-child {
        color: #999;
        font-size: 16px;
      }
    }
  }

  .amount {
    span {
      &:first-child {
        font-size: 16px;
        color: #999;
      }

      &:last-child {
        color: $priceColor;
        font-size: 20px;
      }
    }
  }
}

.pay-type {
  margin-top: 20px;
  background-color: #fff;
  padding-bottom: 70px;

  p {
    line-height: 70px;
    height: 70px;
    padding-left: 30px;
    font-size: 16px;

    &.head {
      border-bottom: 1px solid #f5f5f5;
    }
  }

  .btn {
    width: 150px;
    height: 50px;
    border: 1px solid #e4e4e4;
    text-align: center;
    line-height: 48px;
    margin-left: 30px;
    color: #666666;
    display: inline-block;

    &.active,
    &:hover {
      border-color: $xtxColor;
    }

    &.alipay {
      background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7b6b02396368c9314528c0bbd85a2e06.png) no-repeat center / contain;
    }

    &.wx {
      background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/c66f98cff8649bd5ba722c2e8067c6ca.jpg) no-repeat center / contain;
    }
  }
}
</style>
